﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Jobs_MVC_3_1.Models;

namespace Jobs_MVC_3_1.Controllers
{
    public class ClientCompanyController : Controller
    {
        private JobsEntities db = new JobsEntities();

        //
        // GET: /ClientCompany/
        [Authorize]
        public ViewResult Index()
        {
            return View(db.ClientCompanies.ToList());
        }

        //
        // GET: /ClientCompany/Details/5
        [Authorize]
        public ViewResult Details(int id)
        {
            ClientCompany clientcompany = db.ClientCompanies.Find(id);
            return View(clientcompany);
        }

        //
        // GET: /ClientCompany/Create
        [Authorize]
        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /ClientCompany/Create
        [Authorize]
        [HttpPost]
        public ActionResult Create(ClientCompany clientcompany)
        {
            if (ModelState.IsValid)
            {
                clientcompany.CreatedBy = HttpContext.User.Identity.Name;
                clientcompany.CreatedDate = DateTime.Now;
                clientcompany.Last_UpdatedBy = HttpContext.User.Identity.Name;
                clientcompany.Last_UpdatedDate = DateTime.Now;

                db.ClientCompanies.Add(clientcompany);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(clientcompany);
        }

        //
        // GET: /ClientCompany/Edit/5
        [Authorize]
        public ActionResult Edit(int id)
        {
            ClientCompany clientcompany = db.ClientCompanies.Find(id);
            return View(clientcompany);
        }

        //
        // POST: /ClientCompany/Edit/5
        [Authorize]
        [HttpPost]
        public ActionResult Edit(ClientCompany clientcompany)
        {
            if (ModelState.IsValid)
            {
                db.Entry(clientcompany).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(clientcompany);
        }

        //
        // GET: /ClientCompany/Delete/5
        [Authorize]
        public ActionResult Delete(int id)
        {
            ClientCompany clientcompany = db.ClientCompanies.Find(id);
            return View(clientcompany);
        }

        //
        // POST: /ClientCompany/Delete/5
        [Authorize]
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            ClientCompany clientcompany = db.ClientCompanies.Find(id);
            db.ClientCompanies.Remove(clientcompany);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}